﻿using System.Windows;
using System.Windows.Media;

namespace Socium.Documents.Sociograms {
	class DirectionView : FrameworkElement {
		protected override void OnRender(DrawingContext context) {
			base.OnRender(context);

			var width = ActualWidth;

			var cap_size = new Science.Vector(width/3d, ActualHeight);
			var y = ActualHeight / 2;

			var thickness = Thickness;
			var geometry = Arrow.GetGeometry(new Point(0, y), new Point(width - 1d, y), Caps, thickness, cap_size);
			var pen = new Pen(Stroke, thickness);
			context.DrawGeometry(Fill, pen, geometry);
		}

		public static readonly DependencyProperty FillProperty;
		public static readonly DependencyProperty StrokeProperty;
		public static readonly DependencyProperty DirectionProperty;
		public static readonly DependencyProperty ThicknessProperty;

		static DirectionView() {
			FillProperty = DependencyProperty.Register(
				"Fill", 
				typeof(Brush), 
				typeof(DirectionView), 
				new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)
			);

			StrokeProperty = DependencyProperty.Register(
				"Stroke", 
				typeof(Brush), 
				typeof(DirectionView), 
				new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)
			);

			DirectionProperty = DependencyProperty.Register(
				"Caps", 
				typeof(ArrowCaps), 
				typeof(DirectionView), 
				new FrameworkPropertyMetadata(ArrowCaps.Both, FrameworkPropertyMetadataOptions.AffectsRender)
			);

			ThicknessProperty = DependencyProperty.Register(
				"Thickness", 
				typeof(double), 
				typeof(DirectionView), 
				new FrameworkPropertyMetadata(1d, FrameworkPropertyMetadataOptions.AffectsRender)
			);
		}

		public Brush Fill {
			get { return (Brush) GetValue(FillProperty); }
			set { SetValue(FillProperty, value); }
		}

		public Brush Stroke {
			get { return (Brush) GetValue(StrokeProperty); }
			set { SetValue(StrokeProperty, value); }
		}

		public ArrowCaps Caps {
			get { return (ArrowCaps)GetValue(DirectionProperty); }
			set { SetValue(DirectionProperty, value); }
		}

		public double Thickness {
			get { return (double)GetValue(ThicknessProperty); }
			set { SetValue(DirectionProperty, value); }
		}
	}
}
